<template>
	<view>
		<nav-bar   fontColor="#FFFFFF" title="注销"></nav-bar>
		<uni-search-bar placeholder="用户姓名:" v-model="userName" @confirm="search"></uni-search-bar>
		<!-- <uni-search-bar placeholder="部门机构:" v-model="orgName" @confirm="search"></uni-search-bar> -->
		<mescroll-body ref="mescrollRef" @init="mescrollInit" :down="downOption" @down="downCallback" @up="upCallback"
			:up="upOption">
			<uni-card mode="card">
				<zb-table :columns="column" :stripe="true" :fit="true" :data="dataList" @dele="dele"></zb-table>
			</uni-card>
		</mescroll-body>
		<uni-popup ref="message" type="message">
			<uni-popup-message :type="msgType" :message="messageText" :duration="3000"></uni-popup-message>
		</uni-popup>
		<uni-popup ref="inputDialog" type="dialog">
			<uni-popup-dialog title="提示" :content="'确认注销用户名为：'+ logOutIemName +'的账号吗？'" ref="inputClose"
				@confirm="confirm" mode="base">
			</uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	 
	export default {
		mixins: [MescrollMixin], // 使用mixin (在main.js注册全局组件)
		data() {
			return {
				userName: '',
				orgName: '',
				column: [{
						type: 'index',
						width: 60,
						label: '序号',
						fixed: true,
						align: 'center'
					},
					{
						name: 'userName',
						label: '姓名',
						width: 80,
						emptyString: '暂无数据',
						fixed: true,
						align: 'center'
					},
					{
						name: 'orgName',
						label: '部门',
						emptyString: '暂无数据',
						align: 'center'
					},
					{
						name: 'sex',
						label: '性别',
						filters: {
							0: '男',
							1: '女'
						},
						emptyString: '暂无数据',
						align: 'center'
					},
					{
						name: 'phone',
						label: '手机号',
						emptyString: '暂无数据',
						align: 'center'
					},
					{
						name: 'idCardNo',
						label: '身份证号',
						emptyString: '暂无数据',
						align: 'center'
					},
					{
						name: 'status',
						label: '启用或注销',
						filters: {
							0: '启用',
							1: '注销'
						},
						emptyString: '暂无数据',
						align: 'center'
					},
					{
						name: 'operation',
						type: 'operation',
						label: '操作',
						align: 'center',
						renders: [{
							name: '注销',
							type: 'warn', // type 为custom的时候自定义按钮
							class: "del",
					 	func: 'dele',
						}, ]
					},
				],
				dataList: [],
				downOption: {
					native: false,
					use: true, // 是否启用下拉刷新; 默认true
					auto: true
				},
				upOption: {
					use: true, // 是否启用上拉加载; 默认true
					auto: true,
					noMoreSize: 5, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看
				},
				logOutIemName: '',
				id: '',
				msgType: 'success',
				messageText: '这是一条成功提示'
			}
		},
		onLoad() {

		},
		methods: {
			messageToggle(type, msg) {
				this.msgType = type
				this.messageText = msg
				this.$refs.message.open();
			},
			search() {
				let opts = {
					url: 'sys/sysUser/search',
					method: 'POST'
				};
				let params = {
					userName: this.userName,
					// orgName: this.orgName
				};
				this.$http.httpTokenRequest(opts, params).then(res => {
					if (res.data.code = 200) {
						this.dataList = res.data.data
					} else {
						this.messageToggle('error', '暂无数据')
					}
				})
			},
			upCallback(page) {
				//联网加载数据
				this.loadData(page.num);
			},
			dele(item) {
				console.log(item)
				this.logOutIemName = item.userName
				this.id = item.id
				this.$refs.inputDialog.open();
			},
			confirm() {
				this.$refs.inputDialog.close()
				let opt = {
					url: 'sys/sysUser',
					method: 'PUT'
				};
				let params = {
					id: this.id,
					status: 1
				};
				this.$http.httpTokenRequest(opt, params).then(res => {
					if (res.data.code == 200) {
						this.messageToggle('success', res.data.msg)
					} else {
						this.messageToggle('error', res.data.msg)
					}
				})
			},
			loadData(pageNo) {
				let opts = {
					url: 'sys/sysUser/search/' + pageNo + '/' + 15,
					method: 'POST'
				};
				let params = {
					userName: this.userName,
					companyName: this.companyName
				};
				this.$http.httpTokenRequest(opts, params).then(res => {
						if (res.data.code == 200) {
							this.mescroll.endSuccess(res.data.data.records.length)
							if (pageNo == 1) {
								this.dataList = res.data.data.records;
							} else {
								this.dataList = this.dataList.concat(res.data.data.records);
							}
							console.log(this.dataList)

						} else {
							this.mescroll.endSuccess(0)
							// this.messageToggle('error', '暂无数据')
						}
					})
					.catch(res => {
						this.$refs.mescroll.endErr();
						uni.hideLoading();
					});
			},
		}
	}
</script>

<style>
</style>
